Now let's write some code to show the beam.
So we have a player.
They bought a lot.
They left.
They came back.
We're going to have a beam light up for them to show them where they should go for their lot.
We want the beam only to be visible to the player who owns the lot so that other people don't get confused.
We don't want beams going everywhere.
So this is going to be a client side thing.
Let's go over to our property manager, take a look at that.
And in the property manager, when we enter the game, we're going to have this equip player.
Equip player is where we're going to send a remote event to the client to light up the beam.
This has to be done client side so that only our player can see the beam, only they can see their beam.
Let's make a beam remote event so that we could send messages from our property manager to our client.
So I'm going to go to replicated storage, hit the plus, and then add a remote event and I'm going
to call that Beam Ray.
All right.
Now, in order for us to fire off that remote event, let's go to the top of our property manager.
If you don't remember where it's at, it's in our server script service, and I will get a variable
for replicated storage game, get service, replicated storage, and then a variable for the beam ray.
So it is in replicated storage.
We'll do a wait for child beam ray.
Now get that beam Ray, go back to our equip player and we're going to I'll just paste that beam ray
fire client.
We're going to need some arguments here.
So the first thing I'm going to do is pass in the player that the remote event is going to because we're
sending it to a player.
And then I need the beam itself.
We're going to activate it on, on client side V is a lot and on the lot we have the lot part right,
the gray part, the part for the base.
And then on the lot part we have the beam itself and I'm also going to send a flag.
It's going to be true or false.
I'm going to send it true now.
And that's going to mean on or off.
Do we turn the beam on or do we turn the beam off?
When we touch it?
We're going to turn the beam off.
Now, where should we put the script for the client?
Well, let's go down and look at Starter Player.
Open that up and I'm going to put this in starter player scripts.
So these are client side scripts.
I'm going to hit that plus sign and add a local script.
And then I'm going to call this.
Oh, something easy.
Like Beam script.
I can make this a little bigger so you can see it.
We're going to get replicated.
Storage game.
Get.
Replicated storage.
We are going to get the beam remote event or beam re replicated storage.
Wait for child beam ra.
The Beam re is going to look for the on client event and we'll put an anonymous function in here.
Remember, we pass three arguments the player, the beam itself and then a boolean.
Whether you're turning it on or off, on or off, we don't need the player because we already got to
the player.
So the player is gone.
So the next argument on the list will be the beam itself and then the status, whether it's going to
be true or false.
I'm going to just do beam dot enabled equals status.
And now we could use this script for turning it off too, right?
We'll just put the status whether we want it on or whether we want it off now.
We need to be able to turn the beam off.
The property manager picked up the fact that we own a lot.
We entered the game.
It lit up the beam by sending a remote event to the Beam script.
On the client side, Bam status was true.
Beams lit up.
When we get to the lot, touch the part, we're going to turn the beam off, perhaps use a time or two.
So let's scroll up to our workspace.
Open up that workspace, go to the lock collection, open up your player lot, and the bias script has
all the code, right?
So let's open up by script and I see a lot model.
I don't see that gray part this lot right here.
That's what we need to step on.
So let's get a variable for that.
Let's say local lot.
I'll just call that lot.
That's the lot part there.
Right?
And then we're going to get the lot model lot part nice.
Now let's scroll down here, we'll get the lot touch event, connect that to an anonymous function.
Whatever touched the lot is going to be passed in here.
We could just say other part, right?
And I'm not interested in trees or anybody else walking on this thing.
What I am interested in is if a player touched the part and if it's my player, more specifically the
the lot owner player, right?
So I'll say local player, I'm going to use the game service.
Whoops, I'm going to need an equals sign.
I'm going to use a game service.
And then we got the player service Colon.
There's this get player added from character.
That's kind of crazy.
That's all right though.
We can get the other part and the parent.
That's too big.
You know what?
Should we do this?
Yeah, we'll just shrink that down a little bit.
If the if the thing that touched the part is a foot or something like that, the parents are going to
be the character, then we're going to have a character right here and then get player from character
is going to be able to find the player associated with the character or not.
But if it does, it's going to put that value in here.
If it doesn't find the player associated with it, like if a zombie stepped on it, then it would just
be nil, the player would be nil.
So we'll say if player then well, that's a player, but we got to make sure it's our player, it's
the lot owner player.
So I'm going to say if player and player equals equals the owner, right?
We have an owner.
Oh, good.
I was worried we didn't have an owner variable.
We do though.
We have an owner variable and the owner value is the player.
So.
Then what we can do is send a remote event.
Oh, we need to get replicated storage and stuff like that.
Or we could just do it right here, right?
We might not need it anywhere else.
So I'm going to say local replicated storage game, get service, replicated storage and we'll get a
beam re from replicated storage.
Wait for child beam ray to move that up and then our beam ray.
I got to spell it a little better than that.
We're going to do a fire client.
We're going to pass in the player.
And this time lot is simply lot.
Oh, we need the beam, right?
Not just a lot, but the beam.
The beam.
And then false is going to be.
Hey, turn it off.
All right, let's try this out.
And we should try it with our test server, too, to see if the other player can't turn it off.
There's our beam.
Well, we should check.
Make sure we don't have any errors.
See how that beam is going the whole way, though.
Some people attach the beam to the character itself and that way it disappears as they move forward.
We might want to do that all.
Look at that.
The beam went off.
That's pretty good.